package exception

// 异常处理包

import (
	"fmt"
	"lark/src/object"
)

// 调试 true开启，false关闭(默认)
var debug bool = false

//语法错误：无效语法

// lexer.go 抛出异常
func Lexer(format string, a ...interface{}) *object.Error {
	if debug {
		return &object.Error{Message: fmt.Sprintf(format, a...)}
	}
	return &object.Error{Message: fmt.Sprintf(format, a...)}
}

// parser.go 抛出异常
func Parser(format string, a ...interface{}) *object.Error {
	if debug {
		return &object.Error{Message: fmt.Sprintf(format, a...)}
	}
	return &object.Error{Message: fmt.Sprintf(format, a...)}
}

/**
 * evaluator.go 抛出异常
 * @param code 错误码
 * @param line 错误行
 * @param format 错误信息
 */
func Evaluator(code int, line int, format string, a ...interface{}) *object.Error {
	if debug {
		return &object.Error{Code: code, Line: line, Message: "错误:" + fmt.Sprintf(format, a...)}
	}
	return &object.Error{Code: code, Line: line, Message: "错误:" + fmt.Sprintf(format, a...)}
}
